package net.huashitong.interview.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.interview.dao.NeedSolveProblemDao;
import net.huashitong.interview.entity.NeedSolveProblem;
import net.huashitong.interview.filter.NeedSolveProblemFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NeedSolveProblemService extends StringPKService<NeedSolveProblem> {

    @Autowired
    private NeedSolveProblemDao dao;
    @Autowired
    private SysTableService tableService;
    @Autowired
    private ReadStateService readStateService;

    @Override
    protected BaseDao<NeedSolveProblem, String> getDao() {
        return dao;
    }
    @Override
    protected void beforeSave(NeedSolveProblem obj) {
        obj.setSysId(tableService.updateMaxSysId("t_gis_interviewNeedSolve", null));
    }

    public String getNewFillDate(){
        return dao.getNewFillDate();
    }

    public String getNewProblemId(){
        return dao.getNewProblemId();
    }

    public List<NeedSolveProblem> queryNeedSolve(NeedSolveProblemFilter filter){
        List<NeedSolveProblem> list = dao.queryNeedSolve(filter);
        return list;
    }

    public List<Map<String,Object>> baseResult(List<NeedSolveProblem> list,String userId){
        List<Map<String, Object>> result = new ArrayList<>();
        boolean isRead = false;
        for(NeedSolveProblem needSolveProblem : list){
            Map<String,Object> map = new HashMap<>();
            map.put("sysId",needSolveProblem.getSysId());
            map.put("problemBusiness",needSolveProblem.getProblemBusiness());
            map.put("specificProblem",needSolveProblem.getSpecificProblem());
            map.put("fillDate",needSolveProblem.getFillDate());
            isRead = readStateService.getReadState(needSolveProblem.getSysId(),userId);
            map.put("isRead",isRead);
            result.add(map);
        }
        return result;
    }

}
